--// vim:ts=4:sw=4:noet
--// uptime.lua -- Record uptime of script (and most likely, rmDC++)

if not uptime then
	uptime = {}
	uptime.start = os.time()
	uptime.diff = function()
		return os.difftime( os.time(), uptime.start )
	end
	uptime.format = function()
		local s = uptime.diff()
		local t = os.date( "!*t", s )
		return string.format( "%i day(s) %02i:%02i:%02i",
				s / 86400, t.hour, t.min, t.sec )
	end
end

dcpp:setListener( "ownChatOut", "uptime",
	function( hub, text )
		local s = string.lower( text )
		if text == "/uptime" then
			DC():PrintDebug( "Uptime: "..uptime.format() )
			return 1
		elseif text == "/uptime show" then
			hub:sendChat( "My rmDC++ uptime is: "..uptime.format() )
			return 1
		elseif string.sub(s, 1, 5) == "/help" then
			hub:injectChat( "*** (uptime.lua) /uptime [show]" )
			return 1
		end
	end
)

DC():PrintDebug( "  ** Loaded uptime.lua **" )
